<?php
namespace app\index\controller;

use think\Controller;
use think\facade\View;
use think\Db;
use think\facade\Config;

class TempDemo extends Controller{
	function __construct(){
		parent::__construct();
		Config::set('app_debug',true);
		Config::set('app_trace',true);
	}
	
	function index(){
		$content = 'Hello World';
		
		//两种方法都输出
// 		return $this->display($content);
// 		return $this->view->display($content);

		//通过静态代理输出
		return View::display($content);
	}
	
	/**
	 * 使用视图输出数据
	 */
	function index2($title = 'SunRock'){
		//变量
		$this->assign('title',$title);
		$this->assign(['name'=>'SunRock','age'=>'29']);
		
		//数组
		$data = ['name'=>'SunRock','age'=>'29'];
		$this->assign('data',$data);
		
		//对象
		$obj = new \stdClass();
		$obj->name = 'SunRock';
		$obj->age = '29';
		$this->assign('obj',$obj);
		
		//常量
		define('MY_NAME', 'SunRock');
		$this->assign('MY_NAME',MY_NAME);
		
		return $this->fetch();
	}

	/**
	 * 常用模板标签
	 */
	function index3(){
// 		$students = Db::table('student')->select();
		$students = \app\index\model\Student::all();
		$this->assign('students',$students);
		
		return $this->fetch();
	}
	
	/**
	 * 分页
	 */
	function index4(){
		$students = \app\index\model\Student::paginate(5);
		$this->assign('students',$students);
	
		return $this->fetch();
	}
	
	function zhihu(){
		return $this->fetch();
	}
}